/**  
 * @Title: UnitServiceImpl.java
 * @Package com.xzit.tmms.service.unit
 * @Description: TODO
 * @author 董亮亮
 * @date 2016年6月23日 上午8:37:37
 * @version V1.0  
 */
package com.xzit.tmms.service.unit;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.xzit.tmms.bean.unit.Class;
import com.xzit.tmms.bean.unit.Unit;
import com.xzit.tmms.common.exception.ServiceException;
import com.xzit.tmms.common.page.Page;
import com.xzit.tmms.mapper.unit.ClassMapper;
import com.xzit.tmms.mapper.unit.UnitMapper;

/**
 * @ClassName: UnitServiceImpl
 * @Description: TODO
 * @author 秦冲
 * @date 2016年6月23日 上午8:37:37
 */
@Service("unitService")
public class UnitServiceImpl implements UnitService {

	@Resource
	private ClassMapper classMapper;
	
	@Resource
	private UnitMapper unitMapper;
	
	@Override
	public void addClass(Class clazz) throws ServiceException {
		try {
			classMapper.save(clazz);
		} catch (Exception e) {
			throw new ServiceException(e);
		}
		
	}
	
	@Override
	public Page<Map<String, Object>> queryClass(Page<Map<String, Object>> page) throws ServiceException {
		classMapper.queryClass(page);
		return page; 
	}

	@Override
	public void deleteClass(Integer classId) throws ServiceException {
		try {
			classMapper.delete(classId);
		} catch (Exception e) {
			throw new ServiceException(e);
		}
		
	}
	
	@Override
	public Class getClassById(Integer classId) throws ServiceException {
		try {
			return classMapper.getById(classId);
		} catch (Exception e) {
			throw new ServiceException(e);
		}
	}
	
	@Override
	public void updateClass(Class clazz) throws ServiceException {
		try {
			classMapper.update(clazz);
		} catch (Exception e) {
			throw new ServiceException(e);
		}
		
	}
	
	@Override
	public List<Map<String, Object>> getUnitList() throws ServiceException {
		try {
			return unitMapper.getUnitList();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			throw new ServiceException("获取企业列表失败");
		}
	}
	
	@Override
	public List<Map<String, Object>> getClassList() throws ServiceException {
		try {
			return 	classMapper.getClassList();
		} catch (Exception e) {
			throw new ServiceException("获取班级列表异常");
		}
		
	}
	@Override
	public Page<Map<String, Object>> queryUnit(Page<Map<String, Object>> page) throws ServiceException {
		unitMapper.queryUnit(page);
		return page;
	}
	@Override
	public void deleteUnit(Integer unitId) throws ServiceException {
		try {
			unitMapper.delete(unitId);
		} catch (Exception e) {
			throw new ServiceException(e);
		}
		
	}
	@Override
	public Unit getUnitById(Integer unitId) throws ServiceException {
		try {
			return unitMapper.getById(unitId);
		} catch (Exception e) {
			throw new ServiceException(e);
		}
	}
	@Override
	public void updateUnit(Unit unit) throws ServiceException {
		try {
			unitMapper.update(unit);
		} catch (Exception e) {
			throw new ServiceException(e);
		}
		
	}
	@Override
	public void addUnit(Unit unit) throws ServiceException {
		try {
			unitMapper.save(unit);
		} catch (Exception e) {
			throw new ServiceException(e);
		}
		
	}
	
}
